package pl.krgr.vm2.ui.actions;

import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

import pl.krgr.vm2.ui.mocks.PersistanceMock;
import pl.vm.domain.OfficialTeam;
import pl.vm.domain.Seazon;

import com.opensymphony.xwork2.ActionSupport;

public class SeazonAction extends ActionSupport {

	private static final long serialVersionUID = 1L;

	private String seazonId;
	private List<OfficialTeam> officialTeams = new LinkedList<OfficialTeam>();
	private Seazon seazon;
	
	public String execute() throws Exception {
		seazon = PersistanceMock.getSeazons().getSeazon(seazonId);
		Set<OfficialTeam> teams = seazon.getTeamManager().getOfficialTeams();
		officialTeams.addAll(teams);
		Collections.sort(officialTeams, new Comparator<OfficialTeam>() {

			public int compare(OfficialTeam o1, OfficialTeam o2) {
				return o1.getName().compareTo(o2.getName());
			}
			
		});
		return SUCCESS;
	}

	public List<OfficialTeam> getOfficialTeams() {
		return this.officialTeams;
	}
	
	public String getSeazonId() {
		return seazonId;
	}

	public void setSeazonId(String seazonId) {
		this.seazonId = seazonId;
	}

	public Seazon getSeazon() {
		return seazon;
	}

	public void setSeazon(Seazon seazon) {
		this.seazon = seazon;
	}
	
}
